package com.zjitc.web.controller;

import com.zjitc.pojo.Favorite;
import com.zjitc.pojo.User;
import com.zjitc.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("favorite")
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;

    @RequestMapping("insert")
    @ResponseBody
    public Boolean insert(Favorite favorite){
//        System.out.println(favorite);
        return favoriteService.insertByP_Id(favorite);
    }

    @RequestMapping("delete")
    public String delete(int p_id, HttpSession session){
        favoriteService.deleteByF_id(p_id);
        User user = (User)session.getAttribute("user");
        return "redirect:/shop/page.do?u_id="+user.getU_id();
    }
}
